package com.syqc.monitor.ui.newaddcar

import android.app.Activity
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.syqc.comlib.utils.loadStringImgError
import com.syqc.monitor.databinding.PopupPhotoViewBinding

class PhotoViewPopup(private val context: Activity) : PopupWindow() {

    private val binding = PopupPhotoViewBinding.inflate(LayoutInflater.from(context))

    init {
        contentView = binding.root
        isClippingEnabled = false
        isFocusable = true //popupwindow设置焦点
        setBackgroundDrawable(ColorDrawable(-0x56000000)) //设置背景
        isOutsideTouchable = false //点击外面窗口消失
        width = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的宽
        height = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的高
        binding.flPhotoView.setOnClickListener {
            dismiss()
        }
        binding.ivClose.setOnClickListener { dismiss() }
    }

    fun show(url: String) {
        binding.photoView.loadStringImgError(context, url)
        showAsDropDown(context.window.decorView, Gravity.NO_GRAVITY, 0, 0)
    }

}